/*************************************************************************
 Copyright (C) Unpublished Unis Software, Inc. All rights reserved.
 Unis Software, Inc., Confidential and Proprietary.

 This software is subject to copyright protection
 under the laws of the Public of China and other countries.

 Unless otherwise explicitly stated, this software is provided
 by Unis "AS IS".
 *************************************************************************/
package com.unis.service.attence;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.unis.common.util.TemplateUtil;
import com.unis.dao.IDataSet4iBatis;
import com.unis.model.BaseModel;
import com.unis.model.attence.DutyMotion;

/**
 * @author Administrator (email:raulcsj@163.com)
 * @since 2013-01-31
 */
@Service("dutymotionService")
public class DutyMotionServiceImpl implements DutyMotionService {

    private IDataSet4iBatis iDataSet4iBatis;

    /****************************************
     * Insert a instace of DutyMotion
     ****************************************/
    public void insert(DutyMotion dutymotion) throws Exception {
        dutymotion.setDateid(TemplateUtil.genUUID());
        iDataSet4iBatis.insert(dutymotion);
    }

    /****************************************
     * Update a instace of DutyMotion
     ****************************************/
    public void update(DutyMotion dutymotion) throws Exception {
        iDataSet4iBatis.update(dutymotion);
    }

    /****************************************
     * Delete a instace of DutyMotion
     ****************************************/
    public void delete(DutyMotion dutymotion) throws Exception {
        iDataSet4iBatis.delete(dutymotion);
    }

    /****************************************
     * Insert instaces of SysUser
     ****************************************/
    public void batchInsert(DutyMotion dutymotion) throws Exception {
        throw new RuntimeException("Not yet implement!");
    }

    /****************************************
     * Delete instaces of SysUser
     ****************************************/
    public void batchDelete(DutyMotion dutymotion) throws Exception {
        String statementId = dutymotion.getStatmentId();
        String mainId = dutymotion.getId();
        String[] ids = mainId.split(",");
        List<BaseModel> dutymotionList = new ArrayList<BaseModel>();
        for (String id : ids) {
            DutyMotion model = new DutyMotion();
            model.setStatmentId(statementId);
            model.setId(id.trim());
            dutymotionList.add(model);
        }
        iDataSet4iBatis.batchDelete(dutymotionList);
    }

    /****************************************
     * Query instaces of DutyMotion
     ****************************************/
    public List<BaseModel> queryAsList(DutyMotion dutymotion) throws Exception {
        String queryListStatement = "";
        if (dutymotion.isPaging()) {
            queryListStatement = dutymotion.getStatmentId();
            dutymotion.setStatmentId("DutyMotion.queryRecordsCount");
            BaseModel baseModel = iDataSet4iBatis.queryAsObject(dutymotion);
            dutymotion.setTotalCount(baseModel.getTotalCount());
            dutymotion.setStatmentId(queryListStatement);
        }
        return iDataSet4iBatis.queryAsList(dutymotion);
    }

    /****************************************
     * Query a instaces of DutyMotion
     ****************************************/
    public BaseModel queryAsObject(DutyMotion dutymotion) throws Exception {
        return iDataSet4iBatis.queryAsObject(dutymotion);
    }

    @Resource
    public void setiDataSet4iBatis(IDataSet4iBatis iDataSet4iBatis) {
        this.iDataSet4iBatis = iDataSet4iBatis;
    }
}
